<?php


namespace App\Http\Controllers\user;


use App\Engine\BaseController;
use App\Models\House as HouseModel;
use Illuminate\Http\Request;
use function app\Utils\go;

class Project extends BaseController
{
    private $houseModel;

    public function __construct(Request $request)
    {
        $this->houseModel=new HouseModel();
        parent::__construct($request);
    }
    

    /**id获取项目
     * @return array
     */
    public function get_project_id()
    {
        $res=$this->houseModel->with(["customlist","property","floors","types","collect","around"])->where("id",$this->get["id"])->first();
        return go($res);
    }


    public function get_project()
    {
        $where=[];
        if (isset($this->get["pid"])){
            if($this->get["pid"])
                $where[]=["pid","=",$this->get["pid"]];
        }

        if (isset($this->get["fid"])){
            if($this->get["fid"])
                $where[]=["fid","=",$this->get["fid"]];
        }

        if (isset($this->get["fid"])){
            if($this->get["type"])
                $where[]=["type","=",$this->get["type"]];
        }
        if (isset($this->get["keyword"])){
            if($this->get["keyword"])
                $where[]=['name',"like","%{$this->get['keyword']}%"];
        }
        
        $where[]=["state","=",0];
        
        $res=HouseModel::where($where)->paginate($this->get["num"]);
        return go($res);
    }

}
